<?php

declare(strict_types=1);

namespace App\AdminApi\Module\Admin\Service;

use App\Common\Model\Admin\LogModel;
use App\Common\Query\{SearchIp, SearchTime};
use Hyperf\Database\Model\Builder;
use Zms\Basics\BasicsServe;
use Zms\Unit\Is;

class LogService extends BasicsServe
{
    use SearchIp;
    use SearchTime;

    /**
     * @return LogModel::class
     */
    public static function model(): string
    {
        return LogModel::class;
    }


    /**
     * 行为搜索器
     * @param Builder $query
     * @param $keyword
     * @return void
     */
    public function searchName(Builder $query, $keyword): void
    {
        if (Is::notEmpty($keyword)) {
            if (is_string($keyword)) {
                $query->where('name', 'LIKE', "%$keyword%");
            }
        }
    }


    /**
     * URL搜索器
     * @param Builder $query
     * @param $keyword
     * @return void
     */
    public function searchUrl(Builder $query, $keyword): void
    {
        if (Is::notEmpty($keyword)) {
            if (is_string($keyword)) {
                $query->where('url', 'LIKE', "%$keyword%");
            }
        }
    }
}